
export const FilesType={
		'image/jpeg':'image',
		'image/jpeg':'image',
		'image/png':'image',
		'image/gif':'image',
		'image/webp':'image',
		'image/svg+xml':'svg',
		'audio/mp3':'audio',
		'video/mp4':'video',
		'audio/ogg':'audio',
		'video/webm':'video'
	}
export const generateName= function (length=20) {
	const data =
		["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F",
  "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
  "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
  "s", "t", "u", "v", "w", "x", "y", "z"];
	let nums = "";
	for (let i = 0; i < length; i++) {
		const r = parseInt(Math.random() * 61, 10);
		nums += data[r];
	}
	return nums;
}
export const listToTree=function (data, {idKey='id',parentKey="pid",childrenKey='children',hasChild='hasChild'}={}) {
	let tree = [],childrenOf = {},length = data.length;
	let item,id,parentId;
	for (let i = 0; i < length; i++) {
		item = data[i];
		id = item[idKey];
		parentId = item[parentKey] || 0;
		// every item may have children
		childrenOf[id] = childrenOf[id] || [];
		// init its children
		item[childrenKey] = childrenOf[id];
		if (parentId != 0) {
			// init its parent's children object
			childrenOf[parentId] = childrenOf[parentId] || [];
			// push it into its parent's children object
			childrenOf[parentId].push(item);
		} else {
			tree.push(item);
		}
	}
	data.forEach((item)=>{
		if(item[childrenKey].length===0){
			delete item[childrenKey];
		}else{
			item[hasChild]=true;
		}
		item[hasChild]=true;
	})
	return tree;
}